/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tracker.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : 12 November 2012
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
 */
@Entity
@Table(name = "Comments")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CommentsEntity.findAll", query = "SELECT c FROM CommentsEntity c"),
    @NamedQuery(name = "CommentsEntity.findByCommentId", query = "SELECT c FROM CommentsEntity c WHERE c.commentId = :commentId"),
    @NamedQuery(name = "CommentsEntity.findByCommentContent", query = "SELECT c FROM CommentsEntity c WHERE c.commentContent = :commentContent")})
public class CommentsEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    @Column(name = "CommentId")
    private Integer commentId;
    @Size(max = 1000)
    @Column(name = "CommentContent")
    private String commentContent;
    @JoinColumn(name = "UserId", referencedColumnName = "UserId")
    @ManyToOne(optional = false)
    private UsersEntity userId;
    @JoinColumn(name = "TorrentId", referencedColumnName = "TorrentId")
    @ManyToOne(optional = false)
    private TorrentsEntity torrentId;

    public CommentsEntity() {
    }

    public CommentsEntity(Integer commentId) {
        this.commentId = commentId;
    }

    public Integer getCommentId() {
        return commentId;
    }

    public void setCommentId(Integer commentId) {
        this.commentId = commentId;
    }

    public String getCommentContent() {
        return commentContent;
    }

    public void setCommentContent(String commentContent) {
        this.commentContent = commentContent;
    }

    public UsersEntity getUserId() {
        return userId;
    }

    public void setUserId(UsersEntity userId) {
        this.userId = userId;
    }

    public TorrentsEntity getTorrentId() {
        return torrentId;
    }

    public void setTorrentId(TorrentsEntity torrentId) {
        this.torrentId = torrentId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (commentId != null ? commentId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CommentsEntity)) {
            return false;
        }
        CommentsEntity other = (CommentsEntity) object;
        if ((this.commentId == null && other.commentId != null) || (this.commentId != null && !this.commentId.equals(other.commentId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "tracker.entity.CommentsEntity[ commentId=" + commentId + " ]";
    }

}
